package 回溯;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TTDB
 * @create 2025/9/18
 */
public class subsets {
     public List<List<Integer>> subsets(int[] nums){
        List<List<Integer>> res = new ArrayList<>();
        dfs(res, new ArrayList<>(), nums, 0);
        return res;
     }
     public void dfs(List<List<Integer>> res, List<Integer> path, int[] nums, int start){
        res.add(new ArrayList<>(path));
        // 剪枝这里传递了一个start参数用作剪枝
        for (int i = start; i < nums.length; i++) {
            path.add(nums[i]);
            dfs(res, path, nums, i + 1);
            path.remove(path.size() - 1);
        }
     }
}
